import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:series_play/comm/base/base_state.dart';
import 'package:series_play/pages/bingewatch/controller/binge_watch_list_controller.dart';
import 'package:series_play/widget/app_color.dart';
import 'package:series_play/widget/app_text.dart';

import '../../generated/assets.dart';
import '../../widget/app_image.dart';
import '../../widget/app_refresh_view.dart';
import 'controller/binge_watch_controller.dart';

class BingeWatchListPage extends StatefulWidget {
  const BingeWatchListPage(this.controller, {super.key});

  final BingeWatchController controller;

  @override
  State<BingeWatchListPage> createState() => _BingeWatchListPageState();
}

class _BingeWatchListPageState extends BaseState<BingeWatchListPage> {
  BingeWatchController get _parentController => widget.controller;

  BingeWatchListController get mController =>
      widget.controller.bingeWatchListController;

  @override
  void initState() {
    super.initState();
    mController.onRefresh();
  }

  @override
  Widget buildPage(BuildContext context) {
    return AppRefreshGridView(
      padding: const EdgeInsets.symmetric(horizontal: 16).w,
      listController: mController,
      itemCount: mController.dataList.length,
      crossAxisCount: 3,
      mainAxisSpacing: 10.w,
      crossAxisSpacing: 10.w,
      itemBuilder: (context, index) {
        final img = AspectRatio(
          aspectRatio: 107 / 140,
          child: Stack(
            children: [
              Container(
                width: double.infinity,
                height: double.infinity,
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(8).r,
                  image: DecorationImage(
                    image: NetworkImage(mController.dataList[index]),
                    fit: BoxFit.cover,
                  ),
                ),
              ),

              Positioned(
                bottom: 6.5.w,
                right: 6.5.w,
                child: Visibility(
                  visible: _parentController.isEditModel.value,
                  child: AppImage(
                    Assets.imagesIcCheckboxNormal,
                    size: 15,
                    isShowShadow: true,
                    borderRadius: BorderRadius.circular(15).r,
                  ),
                ),
              ),
            ],
          ),
        );
        return Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            img,
            6.verticalSpace,
            AppText('你好啊你好啊你好啊', maxLines: 2, color: AppColor.white),
            2.verticalSpace,
            Row(
              children: [
                AppText('第1集', fontSize: 13, color: const Color(0xFFD90F52)),
                AppText('/共100集', fontSize: 13, color: AppColor.white),
              ],
            ),
          ],
        );
      },
      onRefresh: mController.onRefreshing,
      onLoad: mController.onLoadingMore,
    );
  }

  @override
  bool hideAppbar() {
    return true;
  }

  @override
  Color getBackgroundColor() {
    return Colors.transparent;
  }

  @override
  bool get wantKeepAlive => true;
}
